function $(sel){
    return document.querySelector(sel);
}
function $a(sel){
    return document.querySelectorAll(sel);
}

$('#submit').addEventListener('click', async function () {
    let form = {
        id: $('#stdid').value.trim(),
        name: $('#name').value.trim()
    }

    if(form.id == '' || form.name == ''){
        alert('学号或姓名为空！')
        return;
    }

    if(isNaN(form.id)){
        alert('学号必须是个数字！')
        return;
    }

    let res = await fetch('/api/regist', {
        method: 'POST',
        body: JSON.stringify(form),
        headers: {
            'content-type': 'application/json'
        }
    })
    let data = await res.json();
    alert(data.msg);
    $('#stdid').value = '';
    $('#name').value = '';
})